import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
// 代理
    server: {
    proxy: {
      "/movieOnInfoList": {
        target: "https://m.maoyan.com/ajax/movieOnInfoList",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/movieOnInfoList/, ""),
      },

      "/comingList": {
        target: "https://m.maoyan.com",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/comingList/, "/ajax/comingList?ci=10&token=&limit=10"),
      },
      "/movieDetail": {
        // fetch("/movieDetail?movieId=1203734")
        target: "https://m.maoyan.com/ajax/detailmovie",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/detailmovie/, ""),
      },
    },
  },
})
